{% extends 'home.html' %}
{% load static %}

{% block content %}
<div class="panel panel-primary">
    <div class="panel-heading">
        <span class="glyphicon glyphicon-user" aria-hidden="true"></span> 账户信息
    </div>
    <div class="panel-body">
        <div class="row">
            <div class="col-md-8">
                <form class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">工程师ID:</label>
                        <div class="col-sm-9">
                            <p class="form-control-static">{{ user.username }}</p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">姓名:</label>
                        <div class="col-sm-9">
                            <p class="form-control-static">{{ user.full_name|default:"未设置" }}</p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">邮箱:</label>
                        <div class="col-sm-9">
                            <p class="form-control-static">{{ user.email|default:"未设置" }}</p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">部门:</label>
                        <div class="col-sm-9">
                            <p class="form-control-static">{{ user.department|default:"未设置" }}</p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">角色:</label>
                        <div class="col-sm-9">
                            <p class="form-control-static">
                                {% if user.role == 1 %}管理员{% else %}用户{% endif %}
                            </p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">权限:</label>
                        <div class="col-sm-9">
                            <p class="form-control-static">
                                {{permissions}}
                            </p>
                        </div>
                    </div>
                </form>
            </div>

            <div class="col-md-4">
                <div class="panel panel-default">
                    <div class="panel-heading">电子签名</div>
                    <div class="panel-body text-center">
                        {% if signature_image %}
                        <img src="{{ signature_image }}" alt="签名图片" class="img-responsive"
                            style="max-height: 150px; margin: 0 auto;">
                        {% else %}
                        <p>暂无签名图片</p>
                        {% endif %}
                        <hr>
                        <form method="post" enctype="multipart/form-data" id="signature-form">
                            {% csrf_token %}
                            <div class="form-group">
                                <input type="file" name="signature" accept="image/*" class="form-control"
                                    id="signature-input">
                            </div>
                            <button type="submit" class="btn btn-primary">上传签名</button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
    .panel-heading {
        font-weight: bold;
        background: linear-gradient(135deg, #337ab7 0%, #286090 100%);
        color: white;
    }

    .form-control-static {
        font-weight: 500;
    }

    .panel {
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    }
</style>
{% endblock %}

{% block js %}
<script>
    $(document).ready(function () {
        $('#signature-input').change(function () {
            var file = this.files[0];
            if (file) {
                var fileType = file.type;
                var validImageTypes = ['image/gif', 'image/jpeg', 'image/png'];
                if (!validImageTypes.includes(fileType)) {
                    alert('请选择有效的图片文件 (JPEG, PNG, GIF)');
                    $(this).val('');
                    return false;
                }
            }
        });
    });
</script>
{% endblock %}